﻿using System.Web.Mvc;
using SportsStore.Domain.Enities;

namespace SportsStore.WebUI.Infrastructure.Binders
{
    public class CartModelBinder:IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            Cart cart = null;
            if (controllerContext.HttpContext.Session != null)
            {
                 cart = (Cart)controllerContext.HttpContext.Session["Cart"];
                if (cart == null)
                {
                    cart = new Cart();
                    controllerContext.HttpContext.Session["Cart"] = cart;
                }
              
            }
            return cart;
        }
    }
}